<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>字段</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding:10px"><h2>无垠式代码生成器生成结果</h2></div>
<div data-options="region:'west',split:true,title:'主菜单'" style="width:156px;padding:0px;">
<div class="easyui-accordion" data-options="fit:true,border:false">
<div title="域对象清单" style="padding:0px" data-options="selected:true">
<div id="mmadmin" data-options="inline:true" style="width: 142px; height: 98%; overflow: hidden; left: 0px; top: 0px; outline: none; display: block;" class="menu-top menu-inline menu easyui-fluid" tabindex="0"><div class="menu-line" style="height: 122px;"></div>
<div onclick="window.location='../pages/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">主页</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/excelWizard.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">生成代码</div><div class="menu-icon icon-add"></div></div>

<div onclick="window.location='../pages/tables.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">表</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/fields.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">字段</div><div class="menu-icon icon-add"></div></div>
</div>
</div>
</div>
</div>
<div data-options="region:'east',split:true,collapsed:true,title:'属性'" style="width:250px;overflow: hidden">
</div>
<div data-options="region:'south',border:false" style="height:50px;background:#A9FACD;padding:10px;text-align: center">火箭船软件工作室版权所有。作者电邮:jerry_shen_sjf@qq.com QQ群:277689737</div>
<div data-options="region:'center',title:'字段清单'">
<div title="搜索面板" class="easyui-panel" style="width:1120px;height:200px">
<form id="ffsearch" method="post">
<table cellpadding="5">
<tr>
<td>字段类型:</td><td><input  class='easyui-textbox' type='text' name='fieldType' id='fieldType' value='' data-options="required:false"/></td>
<td>是否空:</td><td><input class='easyui-textbox' type='text' name='fieldNull' id='fieldNull' value='' data-options="required:false"/></td>
<td>键值:</td><td><input class='easyui-textbox' type='text' name='fieldKey' id='fieldKey' value='' data-options="required:false"/></td></tr>
</tr>
<tr>
<td>默认:</td><td><input  class='easyui-textbox' type='text' name='fieldDefault' id='fieldDefault' value='' data-options="required:false"/></td>
<td>其他:</td><td><input class='easyui-textbox' type='text' name='fieldExtra' id='fieldExtra' value='' data-options="required:false"/></td>

<td>表:</td><td><input  class='easyui-combobox' type='text' name='tableName' id='tableName' data-options="required:false,valueField:'tableName',textField:'tableName',method:'post',url:'../facade/listAllTablesFacade',loadFilter:function(data){return data.rows}"/></td>
</tr>
<tr>
<td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td>
<td>字段名称:</td><td><input class='easyui-textbox' type='text' name='fieldName' id='fieldName' value='' data-options="required:false"/></td>
<td>活跃:</td><td><input class='easyui-textbox' type='text' name='active' id='active' value='' data-options="required:false"/></td></tr>
</tr>
<tr><td colspan="3"><a href="javascript:void(0)" class="easyui-linkbutton" onclick="listAllTableFieldsByTableName()">搜索</a></td></tr>
</table>
</form>
</div>
<table id="dg" class="easyui-datagrid" title="字段清单" style="width:1120px;height:400px" data-options="singleSelect:false,url:'../facade/listAllTableFieldsByTableNameFacade',queryParams:params,method:'post',pagination:false,toolbar:toolbar">
<thead>
<tr>
<th data-options="field:'id',checkbox:true">序号</th>
<th data-options="field:'fieldType',width:80">字段类型</th>
<th data-options="field:'fieldNull',width:80">是否空</th>
<th data-options="field:'fieldKey',width:80">键值</th>
<th data-options="field:'fieldDefault',width:80">默认</th>
<th data-options="field:'fieldExtra',width:80">其他</th>

<th data-options="field:'tableId',width:80">表</th>
<th data-options="field:'description',width:80">描述</th>
<th data-options="field:'fieldName',width:80">字段名称</th>
<th data-options="field:'active',width:80">活跃</th>
</tr>
</thead>
</table>
</div>

<div class="easyui-window" title="新增字段" id="waddField" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:550px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" method="post">
<table cellpadding="5">
<tr><td>字段类型:</td><td><input  class='easyui-textbox' type='text' name='fieldType' id='fieldType' value='' data-options="required:false"/></td></tr>
<tr><td>是否空:</td><td><input  class='easyui-textbox' type='text' name='fieldNull' id='fieldNull' value='' data-options="required:false"/></td></tr>
<tr><td>键值:</td><td><input  class='easyui-textbox' type='text' name='fieldKey' id='fieldKey' value='' data-options="required:false"/></td></tr>
<tr><td>默认:</td><td><input  class='easyui-textbox' type='text' name='fieldDefault' id='fieldDefault' value='' data-options="required:false"/></td></tr>
<tr><td>其他:</td><td><input  class='easyui-textbox' type='text' name='fieldExtra' id='fieldExtra' value='' data-options="required:false"/></td></tr>
<tr><td>表:</td><td><input  class='easyui-combobox' type='text' name='tableName' id='tableName' value='' data-options="required:false,valueField:'tableName',textField:'tableName',method:'post',url:'../facade/listAllTablesFacade',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td></tr>
<tr><td>字段名称:</td><td><input  class='easyui-textbox' type='text' name='fieldName' id='fieldName' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addField()">新增</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#waddField').window('close')">取消</a>
</div>
</div>

<div class="easyui-window" title="编辑字段" id="wupdateField" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:500px;height:500px">
<div style="padding:10px 60px 20px 60px">
<form id="ffedit" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>字段类型:</td><td><input  class='easyui-textbox' type='text' name='fieldType' id='fieldType' value='' data-options="required:false"/></td></tr>
<tr><td>是否空:</td><td><input  class='easyui-textbox' type='text' name='fieldNull' id='fieldNull' value='' data-options="required:false"/></td></tr>
<tr><td>键值:</td><td><input  class='easyui-textbox' type='text' name='fieldKey' id='fieldKey' value='' data-options="required:false"/></td></tr>
<tr><td>默认:</td><td><input  class='easyui-textbox' type='text' name='fieldDefault' id='fieldDefault' value='' data-options="required:false"/></td></tr>
<tr><td>其他:</td><td><input  class='easyui-textbox' type='text' name='fieldExtra' id='fieldExtra' value='' data-options="required:false"/></td></tr>
<tr><td>表:</td><td><input  class='easyui-combobox' type='text' name='tableId' id='tableId' value='' data-options="required:false,valueField:'tableName',textField:'tableName',method:'post',url:'../facade/listAllTablesFacade',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td></tr>
<tr><td>字段名称:</td><td><input  class='easyui-textbox' type='text' name='fieldName' id='fieldName' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateField()">编辑</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#ffedit').form('clear');">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wupdateField').window('close')">取消</a>
</div>
</div>
</body>
<script type="text/javascript">
var params = {};
var pagesize = 10;
var pagenum = 1;
var toolbar = [
];
$(document).ready(function(){
$("#dg").datagrid("load");
});
function clearForm(){
$('#ff').form('clear');
}
function addField(){
	if ($("#ff").form("validate")) {
		$.ajax({
			type: "post",
			url: "../facade/addFieldFacade",
			data:{
				fieldType:$("#ff").find("#fieldType").val(),
				fieldNull:$("#ff").find("#fieldNull").val(),
				fieldKey:$("#ff").find("#fieldKey").val(),
				fieldDefault:$("#ff").find("#fieldDefault").val(),
				fieldExtra:$("#ff").find("#fieldExtra").val(),
				tableId:$("#ff").find("#tableId").combobox("getValue"),
				description:$("#ff").find("#description").val(),
				fieldName:$("#ff").find("#fieldName").val(),
				active:parseBoolean($("#ff").find("input[name='active']:checked").val()),
			},
			success: function(data, textStatus) {
				if (data.success) {
					$('#ff').form('clear');
					$("#ff").find("input[name='active']").get(0).checked = true;
					$("#waddField").window('close');
					$("#dg").datagrid("load");
				}
				},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function(XMLHttpRequest,textStatus,errorThrown) {
				alert("Error:"+textStatus);
				alert(errorThrown.toString());
			}
		});
	}
}

function updateField(){
	$.ajax({
		type: "post",
		url: "../facade/updateFieldFacade",
		data:{
			fieldType:$("#ffedit").find("#fieldType").val(),
			fieldNull:$("#ffedit").find("#fieldNull").val(),
			fieldKey:$("#ffedit").find("#fieldKey").val(),
			fieldDefault:$("#ffedit").find("#fieldDefault").val(),
			fieldExtra:$("#ffedit").find("#fieldExtra").val(),
			tableId:$("#ffedit").find("#tableId").combobox("getValue"),
			description:$("#ffedit").find("#description").val(),
			fieldName:$("#ffedit").find("#fieldName").val(),
			active:parseBoolean($("#ffedit").find("input[name='active']:checked").val()),
			id:$("#ffedit").find("#id").val(),
		},
		success: function(data, textStatus) {
			if (data.success){
				$('#ffedit').form('clear');
				$("#ffedit").find("input[name='active']").get(0).checked = true;
				$("#wupdateField").window('close');
				$("#dg").datagrid("load");
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	}); 
}

function softDeleteField(id){
	$.ajax({
		type: "post",
		url: "../facade/softDeleteFieldFacade",
		data: {
			"id":id	
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function deleteField(id){
	$.ajax({
		type: "post",
		url: "../facade/deleteFieldFacade",
		dataType: 'json',
		data:{"id":id},
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	}); 
}

function toggleField(id){
	$.ajax({
		type: "post",
		url: "../facade/toggleFieldFacade",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function toggleOneField(id){
	$.ajax({
		type: "post",
		url: "../facade/toggleOneFieldFacade",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function softDeleteAllFields(ids){
	$.ajax({
		type: "post",
			url: "../facade/softDeleteAllFieldsFacade",
			data: {
				ids:ids
			},
			dataType: 'json',
			success: function(data, textStatus) {
				$("#dg").datagrid("load");
			},
			complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function deleteAllFields(ids){
	$.ajax({
		type: "post",
		url: "../facade/deleteAllFieldsFacade",
		data: {
			ids:ids
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function listAllTableFieldsByTableName(){
	var data = $("#ffsearch").find("#tableName").combobox("getValue");
	params = {
			tableName:$("#ffsearch").find("#tableName").combobox("getValue"),
		};
	$("#dg").datagrid({queryParams:params});
}

function parseBoolean(val){
	if (val == undefined|| val == null) return false;
	var isInt = /^(-}+)?\d+$/.test(val);
	if (isInt&& val == "0") return false;
	else if (isInt&& val == "1") return true;
	else if (val.toLowerCase() == "false") return false;
	else if (val.toLowerCase() == "true") return true;
	else if (val.toLowerCase() == "f") return false;
	else if (val.toLowerCase() == "t") return true;
	else if (val.toLowerCase() == "n") return false;
	else if (val.toLowerCase() == "y") return true;
	else if (val.toLowerCase() == "no") return false;
	else if (val.toLowerCase() == "yes") return true;
	else return "";
}
function isBlank(val){
	if (val == undefined|| val == null || val == "") return true;
	else return false;
}
function checkRadioBoxValue(control,field,fieldvalue){
	var checkboxs = $("#"+control).find("input[name='"+field+"']");
	for (var i=0;i<checkboxs.size();i++){
		if (checkboxs.get(i).value == ""+fieldvalue) checkboxs.get(i).checked=true;
	}
}
function translateTable(value){
	var retVal = value;
	$.ajax({
		type:"post",
		url: "../facade/findTableByIdFacade",
		data: {
			id:value
		},
		dataType: 'json',
		async:false,
		success: function(data, textStatus) {
			debugger;
			retVal = data.data.tableName;
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
	return retVal;
}
</script>
</html>
